package com.oocl.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.dto.MerchantDTO;
import com.oocl.factory.ServiceFactory;
import com.oocl.log4j.Log4j;
import com.oocl.pojo.Merchant;
import com.oocl.service.MerchantService;
import com.oocl.service.impl.MerchantServiceImpl;
import com.oocl.util.ObjConvertUtil;
import com.oocl.util.URLConnectionUtil;
import com.oocl.vo.MerchantVO;
/**
 * 
 * @author XIEMI2
 *
 */

public class ShowMerchantServlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
	private MerchantService merchantService;
	
	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		merchantService = ServiceFactory.getMerchantService();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		// 从 A 平台 拿到所有白状态的商家信息
		List<MerchantDTO> merchantDTOs =URLConnectionUtil.getAllPassMerchant();
		
		// 完整商家 的头像 信息
		List<Merchant> merchants = merchantService.getMerchants(merchantDTOs);
		
		// 封装成 vo
		List<MerchantVO> merchantVOs = ObjConvertUtil.merchantDOsToVOs(merchants);
		
		request.setAttribute("merchantVOs", merchantVOs);
		request.getRequestDispatcher("view/showMerchant.jsp").forward(request, response);
	}

}
